Yocto

Home > Software Notes > Tools > Toolchains

system shared bitbake cache

sudo useradd --system --no-create-home --shell /usr/sbin/nologin bitbake
sudo mkdir /var/bitbake
sudo chown -R bitbake:bitbake /var/bitbake
chmod -R 2775 /var/bitbake
# set default group permissions for new files
setfacl -R -m d:g:bitbake:rwx /var/bitbake

# add your user to allow acces to cache
sudo usermod -aG bitbake $USER

Now edit your local.conf and add:

DL_DIR="/var/bitbake/downloads"
SSTATE_DIR="/var/bitbake/sstate-cache"

extending machine configuration

Create conf/machine/raspi4-custom.md

# keep the original machine as an override with high prio
MACHINEOVERRIDES =. "raspberrypi4:"
require conf/machine/raspberrypi4.conf
MACHINE_PREFIX_raspi4-custom = "raspberrypi4"


# start of our costumizations:
RPI_USE_U_BOOT = "1"
ENABLE_UART = "1"
Source

modifying kernel configuration

Modify the linux kernel with configuration fragments in Yocto
This also works for U-boot.

minimize rootfs size

Extract the rootfs and have a look at its disk usage using ncdu.

generate dynamic hostname on first boot

Install this service into your image using a recipe.

[Unit]
Description=Generate random hostname on first boot

ConditionFirstBoot=yes
Before=first-boot-complete.target
Wants=first-boot-complete.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'hostnamectl set-hostname "system-$(cat /etc/machine-id | sha256sum | cut -c1-8)"'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

The ConditionFirstBoot is fulfilled if /etc/machine-id is missing. Be default Yocto adds an empty machine-id file to your image. Adding

remove_machine_id() {
    rm -f ${IMAGE_ROOTFS}/etc/machine-id
}
ROOTFS_POSTPROCESS_COMMAND:append = "remove_machine_id "

to your image recipe will not work, because the file is added in the IMAGE_PREPROCESS_COMMAND which is run after the ROOTFS_POSTPROCESS_COMMAND. See the graphic in the docs. Add this instead:

IMAGE_PREPROCESS_COMMAND:remove = "systemd_preset_all"

See this discussion on the mailing list.